# 异常处理：是为了提高代码的健壮性，让代码及时遇到了异常，程序不会终止
# try:
# 可能出现错误的代码块
# except:
# 出错之后执行的代码块
# else:
# 没有出错的代码块
# finally:
# 不管有没有出错都执行的代码块
try:
    list1=["python","java","mysql","C#"]
    print(list1[2])
    pass
except Exception as e:
    print("此处代码出现了异常")
    pass
else:
    print("代码正常运行")
finally:
    print("无论代码是否发生异常都会被执行...")


def a():
    print(1/0)
    pass
def b():
    a()
    pass
def c():
    try:
        b()
        pass
    except Exception as msg:
        print(msg)
        pass
    pass
c()
# 自定义异常
class MyException(Exception):
    def __str__(self):
        return "这是一个自定义异常"
    pass
try:
    num=int(input("请输入一个数字"))
    if num>10:
        # raise将异常向上抛出
        raise MyException
    pass
except MyException as msg:
    print(msg)
    pass
else:
    print("没有出现异常")